#!/usr/bin/env python
import os
import sys
import getopt
'''
picks up all files in unwraps/ and runs the matcher on each one against each other, outputting results to screen.
'''

optlist, args = getopt.getopt(sys.argv[1:],'ld')
matcher = 'matcher.exe'
debug = False

for o in optlist:
	if o[0] == '-l':
		matcher = './matcher'
	if o[0] == '-d':
		debug = True

#if debug:
    #tempFiles = [os.path.join('unwraps',x) for x in os.listdir('unwraps') if not os.path.isdir(x) and os.path.splitext(x)[1] in ['.tif','.tiff','.jpg','.jpeg','.pgm'] ]
    #for i in tempFiles:
        #print i,
    #sys.exit()



files = [os.path.join('unwraps',x) for x in os.listdir('unwraps') if not os.path.isdir(x) and os.path.splitext(x)[1] in ['.tif', '.tiff', '.jpg', '.jpeg', '.pgm'] ]
left = [x for x in files if 'l' in os.path.splitext(x)[0]]
right = [x for x in files if 'r' in os.path.splitext(x)[0]]
left.sort()
right.sort()
#files = [right, left]

if debug:
    for i in left:
        print i,
    for j in right:
        print j,
    sys.exit()

for f in right: print f, ',',
print ''
for probe in right:
    print "%s, " % probe, 
    for gallery in files:
        args  = [matcher, '-g', gallery, '-p', probe]
        os.spawnv( os.P_WAIT, matcher, args )
    print ''

for f in left: print f,',',
print ''
for probe in left:
    print "%s, " % probe, 
    for gallery in files:
        args  = ['matcher.exe', '-g', gallery, '-p', probe]
        os.spawnv( os.P_WAIT, 'matcher.exe', args )
    print ''
